import HTMLParser
import urllib
import re


urlString = "http://cixp.web.cern.ch/cixp/peering_contacts.html"
urlText = []
pathOut = "ixp_members.txt"


class Parse23 (HTMLParser.HTMLParser):
    
    check = False
    
    def handle_starttag (self, tag, attrs):
        if tag == "td":
            for name,value in attrs:
                if name == "style" and value == "vertical-align: top;":
                    self.check = True
    
    def handle_data (self, data):
        if self.check == True:
            m = re.match("^(\d+)\s*$",data)
            if m:
                data = m.group(1)
                if data not in urlText:
                    urlText.append(data)
            self.check = False


lparser = Parse23()
lparser.feed(urllib.urlopen(urlString).read())
fileOut = open(pathOut, "a")
for item in urlText:
    #print item # debug
    print >> fileOut, "23 %s" % item
fileOut.close()